package cn.com.huzo.repository.purchase.impl;

import cn.com.huzo.model.entities.purchase.PoLinesMrpLinesEntity;
import huzofw.repository.impl.GenericRepositoryImpl;
import huzofw.repository.impl.MyBatisDaoUtils;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.springframework.stereotype.Repository;
import cn.com.huzo.repository.purchase.PoLinesMrpLinesRepository;

/**
 * 采购订单-引入的调达表明细数据访问对象。
 *
 * @author 吴旭
 */
@Repository("PoLinesMrpLinesRepository")
public class PoLinesMrpLinesRepositoryImpl extends GenericRepositoryImpl<PoLinesMrpLinesEntity, String>
        implements PoLinesMrpLinesRepository {

    private final String namespace = "cn.com.huzo.repository.purchase.PoLinesMrpLinesRepository";

    /**
     * 构造函数,设置the instance to ProductRepositoryImpl.class.
     */
    public PoLinesMrpLinesRepositoryImpl() {
        super(PoLinesMrpLinesEntity.class);
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public Integer fetchForCount(Map<String, Object> criterion) {
        return getSqlSession().selectOne(MyBatisDaoUtils.getMapperQueryId(
                namespace, "fetchForCount"), criterion);
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public List<PoLinesMrpLinesEntity> fetchForPage(Map<String, Object> criterion) {
        return getSqlSession().selectList(MyBatisDaoUtils.getMapperQueryId(
                namespace, "fetchForPage"), criterion);
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public List<String> fetchPoStyleNoByPoHeaderId(long poHeaderId) {
        return getSqlSession().selectList(MyBatisDaoUtils.getMapperQueryId(
                namespace, "fetchPoStyleNoByPoHeaderId"), poHeaderId);
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public Integer insertLines(Long headerId, Long updatedBy,
            List<String> mrpLinesIdList, Short separateFlagByPartOfNeed) {
        Map<String, Object> criterion = new HashMap();
        criterion.put("HeaderId", headerId);
        criterion.put("MrpLinesIdList", mrpLinesIdList);
        criterion.put("SeparateFlagByPartOfNeed", separateFlagByPartOfNeed);
        criterion.put("CreatedBy", updatedBy);
        criterion.put("UpdatedBy", updatedBy);

        return getSqlSession().insert(MyBatisDaoUtils.getMapperQueryId(
                namespace, "insertLines"), criterion);
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public Integer deleteInvalidRow(Long headerId) {
        return getSqlSession().delete(MyBatisDaoUtils.getMapperQueryId(
                namespace, "deleteInvalidRow"), headerId);
    }
}
